//快捷支付
$(function() {
	var param = {};
	//获取邮箱用于给邮箱发送验证码
	$.ajax({
		url : '/web-adv/gainEmailAndPwd',
		data : param,
		type : 'POST',
		dataType : "json",
		success : function(data) {
			$("#email").val(data.email);
			var email=data.email;
        sendVerCode(email);
		},
		error : function(data) {
		}
	});			
});

var countdown;
var timer=null;
/**倒计时**/
function timeGo(){
	 countdown=60;	
	 $("#sendAgain").attr("disabled",true);
	 timer=setInterval(function(){
			countdown--;
			$("#sendAgain").html(countdown+'s');
			if (countdown <= 0) {
				$("#sendAgain").html("重新获取");
				clearInterval(timer);
				 $("#sendAgain").attr("disabled",false);
			};
	 }, 1000);	
};

//重新发送验证码
$("#sendAgain").click (function(){
	$("#error_tip2").html("");
	timeGo();//倒计时
	var email=$("#email").val();
	sendVerCode(email);
});

//给邮箱发送验证码
function sendVerCode(email){
	$.ajax({
		url : "/web-adv/sendEmailVerCode",
		type : "POST",
		dataType : "json",
		data : {
			"email" : email
		},
		success : function(json) {
			if (json.status == 1) { // 1 邮件发送成功
				
			} else if (json.status == -1) { // -1 邮件发送失败
				$("#error_tip2").html(json.error);
			}
		},
		error : function(json) {
		}
	});
}
	
//邮箱验证码校验
$("#nextStep").click(function(){
	var email=$("#email").val(), code= $("#verCode").val();
	var param={"email":email,"verCode":code};
	if(!code){
		$("#error_tip2").html("*请输入验证码");  	
	}else{
		$.ajax({
			url:"/web-adv/checkEmail",
			type:"POST",
			dataType:"json",
			data:param,
		    success : function(json) {
		    	if(json.status==1){ //验证码正确 ，跳转页面 	
		    		var path=escape('selectedNav=0&navPos=3');
		    		window.location.href = "/web-adv/advWeb/views/userCenter/recharge/setPayPwd.html?"+path;
		    	}else if(json.status==-1){ // -1 验证码输入错误
		    		$("#error_tip2").html(json.error);  	
		    	}
		    },
	        error: function(json){
	        }     
	   });
	}
 });





